<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp_lib/init.jsp"%>

<script type="text/javascript">
	var add_form_panel = Ext.create("Ext.form.Panel", {
		url : "add.htm",
		buttonAlign : "center",
		bodyStyle : "padding: 5px;",
		defaultType : "textfield",
		width:500,
		items : [ {
			id : 'code_code',
			fieldLabel : "验证码",
			labelStyle : "text-align:right;",
			labelWidth : 60,
			name : "code.code",
			xtype : "textfield",
			readOnly : true,
			width:'100%',
			allowBlank : false
		}, {
			xtype : "fieldcontainer",
			layout : "column",
			items : [ {
				fieldLabel : "有效天数",
				labelStyle : "text-align:right;",
				labelWidth : 60,
				name : "day",
				xtype : "numberfield",
				allowBlank : false
			}, {
				fieldLabel : "金额",
				labelStyle : "text-align:right;",
				labelWidth : 60,
				name : "code.money",
				xtype : "numberfield",
				allowBlank : false
			} ]
		}, {
			xtype : "fieldcontainer",
			layout : "column",
			items : [ {
				fieldLabel : "验证人姓名",
				name : "code.verify_name",
				labelStyle : "text-align:right;",
				labelWidth : 60,
				xtype : "textfield"
			}, {
				fieldLabel : "验证人 qq",
				name : "code.verify_qq",
				labelStyle : "text-align:right;",
				labelWidth : 60,
				xtype : "textfield",
			} ]
		}, {
			xtype : "fieldcontainer",
			layout : "column",
			items : [ {
				fieldLabel : "联系手机号",
				name : "code.verify_mobile",
				labelStyle : "text-align:right;",
				labelWidth : 60,
				xtype : "textfield"
			}, {
				fieldLabel : "联系人邮箱",
				name : "code.verify_email",
				labelStyle : "text-align:right;",
				labelWidth : 60,
				xtype : "textfield",
			} ]
		}, {
			xtype : "fieldcontainer",
			layout : "column",
			items : [ {
				fieldLabel : "备注",
				name : "code.note",
				labelStyle : "text-align:right;",
				labelWidth : 60,
				xtype : "textarea"
			} ]
		}

		],
		buttons : [ {
			text : "保存",
			formBind : true, //only enabled once the form is valid
			disabled : true,
			handler : function() {
				var form = this.up("form").getForm();
				if (form.isValid()) {
					form.submit({
						waitMsg : "保存中...",
						success : function(form, action) {
							Ext.Msg.alert("提示", action.result.tip.msg);
							add_form_panel_win.close();
							dataStore.load();
						},
						failure : function(form, action) {
							Ext.Msg.alert("提示", action.result.tip.msg);
						}
					});
				}
			}
		} ]
	});

	var add_form_panel_win = Ext.create("Ext.Window", {
		title : "验证码添加",
		closeAction : "hide",
		items : add_form_panel
	});

	function myAdd() {
		add_form_panel.getForm().reset();
		add_form_panel_win.show();

		Ext.Ajax.request({
			url : "get_code.htm",
			success : function(response) {
				var json = Ext.util.JSON.decode(response.responseText);
				edit_form_panel.getForm().setValues(json);

				Ext.getCmp('code_code').setValue(json.system_code);
			},
			failure : function(response) {
				Ext.Msg.alert("提示", "操作失败!");
			}
		});
	}
</script>
